package cn.weiron.fun.infrastructure;

/**
 * Return to the content wrapper,
 * wrap the returned data as a custom structure and return.
 *
 * @author 马强
 */
public interface ResponseWrapper {
    /**
     * Check if the specified object is a wrapped object.
     *
     * @param object Can not be empty
     * @return If empty, the default is true
     */
    default boolean isObjectAfterWrap(Object object) {
        return (object instanceof ResponseDefault);
    }

    /**
     * wrap the returned data as a custom structure and return.
     *
     * @param message return description
     * @param data    Arbitrary object
     * @return Wrapped output object
     */
    default Object wrap(String message, Object data) {
        return new ResponseDefault(true, "200",message,data);
    }

    /**
     * wrap the returned data as a custom structure and return.
     *
     * @param code  return status code
     * @param message return description
     * @return Wrapped output object
     */
    default Object wrap(String code, String message) {
        return new ResponseDefault("200".equals(code),code, message, null);
    }

    /**
     * Default content wrapper implementation.
     */
    class Default implements ResponseWrapper {
    }
}